// pages/course_detail/course_detail.js
const app = getApp();
var router = require("../../router.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
  
  },
  buy() {
    var that = this;
    app.request({
      url: router.course.add,
      method: "POST",
      data: {
        id: that.data.list.id,
        user_id: wx.getStorageSync('userInfo').id
      },
      success: function (data) {      
        if (data.status == true) {
          wx.showToast({
            title: '操作成功发起支付',
            icon: 'none',
            mask: true,
            duration: 2000
          });
        } else {
          wx.showToast({
            title: '操作失败',
            icon: 'none',
            mask: true,
            duration: 2000
          });
        }
      }
    })  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      course_id: options.id
    });   
  },
  onShow: function () {
    this.getInfo();
  },
  getInfo: function () {
    var that = this;
    app.request({
      url: router.course.info,
      method: "POST",
      data: {
        id: that.data.course_id,
      },
      success: function (data) {
        console.log(data);      
        if (data.status == true) {
          that.setData({
            list: data.list,
          });          
        } else {
          wx.showToast({
            title: '获取信息失败',
            icon: 'none',
            mask: true,
            duration: 2000
          });
        }
      }
    })
  }
})